<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        class Dictionay {
            constructor() {
                this.items = {} //字典属性
            }

            //字典操作
            //在字典中添加键值对
            set(key, value) {
                this.items[key] = value;
            }
            //判断字典中是否有某个key
            has(key) {
                return this.items.hasOwnProperty(key);
            }
            //从字典移除元素
            remove(key) {
                //1.判断字典中是否有这个key
                if (!this.has(key)) return false;

                //2.从字典中删除key
                delete this.items[key];
                return true;
            }
            //根据key获取value
            get(key) {
                return this.has(key) ? this.items[key] : undefined;
            }
            //获取所有的keys 健
            keys() {
                return Object.keys(this.items)
            }
            //返回字典包含的所有的值
            values() {
                let key = this.keys();
                let value = []
                for(let i = 0; i < key.length; i++) {
                    value.push(this.get(key[i]))
                }
                return value;
            }
            //返回数组中所有的健值
            keyValues() {
                let keysValues = []
                for(let i in this.items) {
                    if(this.has(i)) {
                        keysValues.push(i)
                    }
                }
                return keysValues
            }
            //size方法
            size() {
                return this.keys().length;
            }
            //clear方法
            clear() {
                this.items = {};
            }
        }

        let dict = new Dictionay();
        dict.set("name","leilei")
        dict.set("hight",1.88)
        dict.set("age",18)
        console.log(dict);
        console.log(dict.get("name"));
        console.log(dict.keys());
        console.log(dict.values());
        console.log(dict.keyValues());

        let array = [23,88,12,566,100,5,66,87];
        let i = 0;
        let j = 6;
        console.log(++i);
        while(array[++i] < 66) {}
        while(array[j--] > 66) {}
        console.log(i,j);
    </script>
    
</body>

</html>